package crons

import (
	"context"
	"go.didapinche.com/foundation/plat-echo/app/ops/services"
	"go.uber.org/zap"
)

type ClearRepearHistoryJob struct {
	logger  *zap.Logger
	service services.AlertHistoryService
}

func NewClearRepearHistoryJob(logger *zap.Logger, service services.AlertHistoryService) *ClearRepearHistoryJob {
	job := &ClearRepearHistoryJob{
		logger:  logger,
		service: service,
	}
	return job
}

//定期删除重复消息
func (a *ClearRepearHistoryJob) Run() {
	a.logger.Info("api info job start")
	ctx := context.Background()
	err := a.service.DeleteByRepeat(ctx)
	if err != nil {
		a.logger.Error("call apiService.GetApiByApp error", zap.Error(err))
	}
}

func (a *ClearRepearHistoryJob) Init() {
	a.Run()
}

//每天
func (a *ClearRepearHistoryJob) Cron() string {
	return "0 0/2 * * * ?"
}

func (a *ClearRepearHistoryJob) Name() string {
	return "api_info"
}
